package com.mzw.huaxiarealestatebackend.controller;

import com.mzw.huaxiarealestatebackend.common.utils.DataResult;
import com.mzw.huaxiarealestatebackend.entity.BackPage;
import com.mzw.huaxiarealestatebackend.entity.Client;
import com.mzw.huaxiarealestatebackend.entity.ProjectProcess;
import com.mzw.huaxiarealestatebackend.entity.Result;
import com.mzw.huaxiarealestatebackend.service.ProjectProcessService;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (ProjectProcess)表控制层
 *
 * @author makejava
 * @since 2023-12-22 00:03:03
 */
@RestController
@RequestMapping("projectProcess")
public class ProjectProcessController {
    /**
     * 服务对象
     */
    @Resource
    private ProjectProcessService projectProcessService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public DataResult queryById(@PathVariable("id") Integer id) {
        ProjectProcess projectProcess = this.projectProcessService.queryById(id);
        if (projectProcess != null){
            return DataResult.ok(projectProcess);
        }
        return DataResult.failure("查找失败");
    }

    /**
     * 新增数据
     *
     * @param projectProcess 实体
     * @return 新增结果
     */
    @PostMapping
    public Result<ProjectProcess> add(@RequestBody ProjectProcess projectProcess) {
        boolean insert = this.projectProcessService.insert(projectProcess);
        if (insert){
            return Result.success();
        }
        return Result.error("添加失败");
    }

    /**
     * 编辑数据
     *
     * @param projectProcess 实体
     * @return 编辑结果
     */
    @PutMapping
    public Result<ProjectProcess> edit(@RequestBody ProjectProcess projectProcess) {
        boolean update = this.projectProcessService.update(projectProcess);
        if (update){
            return Result.success();
        }
        return Result.error("修改失败");
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public Result<ProjectProcess> deleteById(@RequestParam("id") Integer id) {
        boolean b = this.projectProcessService.deleteById(id);
        if (b){
            return Result.success();
        }
        return Result.error("删除失败");
    }

}

